package Thread;

public class ThreadDemo7 {

    public static boolean isQuit = false;

    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(() -> {
            while (!isQuit) {
                System.out.println("thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("线程执行完毕");
        },"测试线程1");

        thread.start();
        // 运行三秒
        Thread.sleep(3000);
        System.out.println("提前终止线程");
        isQuit = true;
    }
}
